package com.example.dictdemo.common.enums;

import com.example.dictdemo.aspect.annotation.EnumDict;
import com.example.dictdemo.enhance.EnumDictMethodEnhance;
import com.example.dictdemo.model.vo.DictModel;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * %s（%s）级别枚举
 *
 * @author dlp
 * @date 2024/08/23
 */
@EnumDict(value = "level")
@Getter
public enum LevelEnum implements EnumDictMethodEnhance {
  FIRST_LEVEL("first_level", "一级"),
  SECOND_LEVEL("second_level", "二级"),
  THIRD_LEVEL("third_level", "三级"),
  FOUR_LEVEL("four_level", "四级"),
  FIFTH_LEVEL("fifth_level", "五级"),
  SIX_LEVEL("six_level", "六级"),

  ;


  private String key;

  private String title;

  LevelEnum(String key, String title) {
    this.key = key;
    this.title = title;
  }

  /**
   * 获取字典列表
   *
   * @return 列表<字典模型>
   */
  @Override
  public List<DictModel> getDictList() {
    List<DictModel> list = new ArrayList<>();
    for (LevelEnum e : LevelEnum.values()) {
      DictModel dictModel = new DictModel();
      dictModel.setValue(e.getKey());
      dictModel.setText(e.getTitle());
      list.add(dictModel);
    }
    return list;
  }

  /**
   * 有效
   *
   * @return boolean
   */
  @Override
  public boolean isValid(String key) {
    if (key == null) {
      return false;
    }
    for (LevelEnum levelEnum : LevelEnum.values()) {
      if (levelEnum.getKey().equals(key)) {
        return true;
      }
    }
    return false;
  }


}
